<% include ../header.ejs %>
<div class="row">
    <div class="col-md-12">
        <div class="box box">
            <div class="box-header with-border">
                <h3 class="box-title">用户列表</h3>
                <div class="box-form">
                    <hr>
                    <form class="form-inline" method="get">
                        <div class="form-group">
                            <label for="keywords">关键词类型：</label>
                            <select name="type" class="form-control">
                                <option value="username" <%if(req.query.type == "username"){%> selected <%}%>>用户名</option>
                                <option value="email" <%if(req.query.type == "email"){%> selected <%}%>>邮箱</option>
                                <option value="id" <%if(req.query.type == "id"){%> selected <%}%>>ID</option>
                            </select>    
                            <input type="text" name="keywords" class="form-control" value="<%-req.query.keywords%>" >
                        </div>
                        <div class="form-group">
                            <select name="usergroup" class="form-control">  
                                <option value="">用户组</option>
                                <%groups.forEach(function(one, key) {%>
                                    <option value="<%-one.id%>" <% if(req.query.usergroup == one.id){ %> selected <%}%> > <%=__(one.varname)%></option>
                                <%})%>
                            </select>
                        </div>
                        <button type="submit" class="btn btn-warning">搜 索</button>
                    </form>
                </div>
            </div>
            <div class="box-body dataTables_wrapper form-inline dt-bootstrap" >
                <div class="row">
                    <div class="col-sm-12">
                        <div class="row clearfix">
                            <div class="col-sm-12">
                                <button href="/admin/user/d_add" class="btn  btn-primary btn-form">添加用户</button>
                            </div>
                        </div>
                        <hr>
                        <table  class="table table-bordered table-striped dataTable" role="grid" >
                            <thead>
                                <tr role="row">
                                    <th>ID</th>
                                    <th>用户名</th>
                                    <th>邮箱</th>
                                    <th>真实姓名</th>
                                    <th>手机</th>
                                    <th>注册时间</th>
                                    <th>最后登录</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <%data.forEach(function(one, key) {%>
                                <tr role="row" class="color-palette">
                                    <td><%=one.id%></td>
                                    <td><%=one.username%></td>
                                    <td><%=one.email%></td>
                                    <td><%=one.realname%></td>
                                    <td><%=one.mobile%></td>
                                    <td><%=dateFormat(one.createtime)%></td>
                                    <td><%=dateFormat(one.lasttime)%></td>
                                    <td><%=__("status_"+one.status)%></td>
                                    <td>
                                        <a class="btn-form" href="/admin/user/d_update/<%=one.id%>">编辑</a>
                                        <a href="/admin/user/delete/<%=one.id%>" onclick="if(!confirm('删除后不可恢复,确定删除纪录吗?'))return false;">删除</a>
                                    </td>
                                </tr>
                                <%})%>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- jquery 表单异步提交 -->
<script type="text/javascript" src="/lib/jquery.form.js"></script>
<script type="text/javascript">
$(document).on("submit",".ajax_form form",function () {
    $(".ajax_form form").ajaxSubmit({
        success: function (data) {
        if(typeof data === "object" && data.result){
            window.location.reload();
        }
        if(typeof data === "string"){
                $(".ajax_form").replaceWith(data);
            }
        }
    });
    return false;
});
</script>
<% include ../footer.ejs %>